/*
 *
 * Copyright (c) 2001-2018 泛微软件.
 * 泛微协同商务系统,版权所有.
 * 
 */
package com.engine.demo.cmd;


import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.constant.*;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.demo.dao.DemoDao;
import com.engine.systeminfo.util.DataUtils;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import java.util.Date;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @version 1.0
 * @author AndyZhang
 * TODO 
 */
public class DoUpdateDemoCmd extends AbstractCommonCommand<Map<String,Object>> {

	private final static Log log = LogFactory.getLog(DoUpdateDemoCmd.class);
			
    private BizLogContext bizLogContext = new BizLogContext();


    public DoUpdateDemoCmd(Map<String,Object> params,User user) {
        this.params = params;
        this.user = user;
    }

    @Override
    public BizLogContext getLogContext() {
        String ruleid = Util.null2String(params.get("id"));
        String _flagInfo = "更新";
        bizLogContext.setDateObject(new Date());
        bizLogContext.setUserid(user.getUID());
        bizLogContext.setUsertype(Util.getIntValue(user.getLogintype()));
        bizLogContext.setTargetId(ruleid);
        bizLogContext.setLogType(BizLogType.SYSTEM_ENGINE);
        bizLogContext.setLogSmallType(BizLogSmallType4SysEngine.SYSTEM_ENGINE_EM);
        bizLogContext.setOperateType(BizLogOperateType.UPDATE);
        bizLogContext.setParams(params);
        bizLogContext.setClientIp(Util.null2String(params.get(ParamConstant.PARAM_IP)));
        bizLogContext.setDesc(String.format(user.getLastname() + "对：规则管理做了"+_flagInfo+"操作， "+_flagInfo+"的mapid是：{"+ruleid+"}  "));
        return bizLogContext;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
    	WeaResultMsg result=new WeaResultMsg(true);

        String id = Util.null2String(params.get("id"));//默认不可修改
        String corp_id = Util.null2String(params.get("corp_id"));
        String oa_name = Util.null2String(params.get("oa_name"));
        String oa_address = Util.null2String(params.get("oa_address"));
        String em_name = Util.null2String(params.get("em_name"));
        String em_url = Util.null2String(params.get("em_url"));
        String remark = Util.null2String(params.get("remark"));
        String date = DataUtils.getNowDate();
        String time = DataUtils.getNowTime();

        String sql =DemoDao.getUpdate();
        RecordSet recordSet = new RecordSet();
        try{
            recordSet.executeUpdate(sql,corp_id,oa_name,oa_address,em_name,em_url,remark,date,time,id);
            result.success();
        }catch(Exception e){
            e.printStackTrace();
            log.error(e);
            result.fail(e.getMessage());
        }
        return result.getResultMapAll();
    }
}
